/* jshint esversion:6 */
/**
 * @author: errorcpp@qq.com
 */

var xwindow = ("undefined" != typeof(window)) ? window : global;
xwindow.xlib = xwindow.xlib || {};
let xlib = xwindow.xlib;


/**
 * @brief: ArrayBuffer数据拷贝
 * @param {ArrayBuffer} arrbuf_src: 源buffer
 * @param {number} begin_src:       源buffer开始位置
 * @param {number} end_src:         源buffer结束位置
 * @param {ArrayBuffer} arrbuf_tar: 目标buffer
 * @param {number} begin_tar:       目标buffer开始位置
 */
xlib.ArrayBuffer_DataCopy = function(arrbuf_src, begin_src, end_src, arrbuf_tar, begin_tar) {
    if(begin_tar === void 0) 
        begin_tar = 0;
    if((end_src - begin_src < 0) || (arrbuf_src.byteLength < end_src) || 
        (end_src - begin_src + begin_tar > arrbuf_tar.byteLength)) {
        throw "rang error";
    }

    let bytes_to_be_copy = end_src - begin_src;
    let dv_src = new Uint8Array(arrbuf_src);
    let dv_tar = new Uint8Array(arrbuf_tar);
    for(let n = 0; n < bytes_to_be_copy; ++n) {
        dv_tar[begin_tar + n] = dv_src[begin_src + n];
    }
};